﻿using System;
using System.Collections.Generic;
using System.Web;

using Net.DataAccess;

namespace Net.BusinessLogic
{
	public class Category : BizObject
	{
		private long _id = 0;
		public long ID { get { return _id; } set { _id = value; } }

		private DateTime _addedDate = DateTime.Now;
		public DateTime AddedDate { get { return _addedDate; } set { _addedDate = value; } }

		private string _addedBy = "";
		public string AddedBy { get { return _addedBy; } set { _addedBy = value; } }

		private string _typeID = "";
		public string TypeID { get { return _typeID; } set { _typeID = value; } }

		private string _name = "";
		public string Name { get { return _name; } set { _name = value; } }

		public Category(long id, DateTime addedDate, string addedBy, string typeID, string name)
		{
			_id = id;
			_addedDate = addedDate;
			_addedBy = addedBy;
			_typeID = typeID;
			_name = name;
		}

		public static Category FindByID(long id)
		{
			Category obj = null;
			string key = "category_" + id.ToString();
			if (Globals.Settings.EnableCaching && Cache[key] != null)
				obj = (Category)Cache[key];
			else
			{
				obj = Get(Provider.Category.FindByID(id));
				CacheData(key, obj);
			}
			return obj;
		}

		/*******************
		 * PRIVATE METHODS *
		 *******************/
		private static Category Get(CategoryDetails r)
		{
			if (r == null) return null;
			return new Category(r.ID, r.AddedDate, r.AddedBy, r.TypeID, r.Name);
		}
		private static List<Category> GetList(List<CategoryDetails> rs)
		{
			List<Category> items = new List<Category>();
			foreach (CategoryDetails r in rs)
				items.Add(Get(r));
			return items;
		}
	}
}